<template>
  <div>

	<myheader></myheader>

	<section class="featured-block text-center">
		<div class="container">
			<Breadcrumb :datas='datas'></Breadcrumb>
			<table>
                <tr>
                    <td>商品名称：<input type="text" v-model="name"></td>
                </tr>
                <tr>
                    <td>简介: <textarea v-model="desc"></textarea></td>
                </tr>
                <tr>
                    <td>价格: <input type="text" v-model="price"></td>
                </tr>
                <tr>
                    <td>分类：
                        <Select :datas='cate_list' v-model="def">
 
                        </Select>
                    </td>
                </tr>
                <tr>
                    <td>
                        商品标签：
                        <TagInput v-model="mytags" type='string' split=',' placeholder='请输入便签'>

                        </TagInput>
                    </td>
                </tr>
                <tr>
                    <td>
                        商品规格&nbsp;&nbsp;&nbsp;
                        <span v-show="def == '衣服'">薄厚: <input type="text" v-model="thickness">面料：<input type="text" v-model="plus"></span>
                        <span v-show="def == '电器'">型号：<input type="text" v-model="model">寿命：<input type="text" v-model="life"></span>   
                        <span v-show="def == '食品'">产地：<input type="text" v-model="place">保质：<input type="text" v-model="guarantee"></span>
                    
                    </td>
                </tr>
                <tr>
                    <td>
                        <Button @click="add">添加</Button>
                    </td>
                </tr>


            </table>

		</div>
	</section>

    <myfooner></myfooner>

    
  </div>
  
</template>


 
<script>
import myheader from './myheader'
import myfooner from './myfooner'
import {config} from '../config'

export default {
  data () {
    return {
      adminurl:config['adminurl'],
      datas:[{title:"首页",route:{name:"index"}},{title:"添加商品"}],
      // 商品参数
      name:"",
      desc:"",
      price:"",
      cate_id:"",
      // 分类
      cate_list:[],
      cate_dic:{},
      def:'电器',
      thickness:"",   //薄厚
      plus:"",   //面料
      model:"",  //型号
      life:"",   //寿命
      place:"",   //产地
      guarantee:"",  //保质
      mytags:""

    }
  },
  components:{
	  "myheader":myheader,
	  "myfooner":myfooner,

  },
  mounted:function(){
      this.getcate()
   
  
},
  methods:{
      add(){
          let parms = {}
          if(this.def == '电器'){
              parms['型号'] = this.thickness
              parms['寿命'] = this.plus
          }else if(this.def == '衣服'){
              parms['薄厚'] = this.model
              parms['面料'] = this.life
          }else if(this.def == '食品'){
              parms['产地'] = this.place
              parms['保质'] = this.guarantee
          }
          parms = JSON.stringify(parms)
          
          this.axios({
              url:this.adminurl + "/insertgoods/",
              method:"POST",
              data:{
                  name:this.name,
                  desc:this.desc,
                  cate_id:this.cate_dic[this.def],
                  price:this.price,
                  params:parms
              }
          })
          .then(res=>{
              console.log(res)
              this.$Message(res.data.message)
              if(res.data.id){
                  this.addtags(res.data.id)
              }
              
          })
      },
      getcate(){
          this.axios({
              url:this.adminurl+"/cate/",
          })
          .then(res=>{
              console.log(res)
              for(let i=0;i<res.data.length;i++){
                  this.cate_list.push(res.data[i].name)
                  this.cate_dic[res.data[i].name] = res.data[i].id
              }
          })
      },
      addtags(id){
          this.axios({
              url:this.adminurl+"/inserttags/",
              params:{
                  id:id,
                  tags:this.mytags
              }
          })
          .then(res=>{
              console.log(res)
          })
      }
     
  }
}


</script>
 
<style>



</style>